//package com.talent.web.config.drools;
//
//import org.kie.api.KieBase;
//import org.kie.api.KieServices;
//import org.kie.api.builder.*;
//import org.springframework.core.io.Resource;
//import org.kie.api.runtime.KieContainer;
//import org.kie.api.runtime.KieSession;
//import org.kie.internal.io.ResourceFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//
//import java.io.IOException;
//
///**
// * @Author: hszhou
// * @Date: 2025/4/18 9:04
// * @Description: 必须描述类做什么事情, 实现什么功能
// */
//@Configuration
//public class DroolsConfig {
//    private static final String RULES_PATH = "drools/";
//
//    @Bean
//    public KieFileSystem kieFileSystem() throws IOException {
//        KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();
//        for (Resource file : getRuleFiles()) {
//            kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), "UTF-8"));
//        }
//        return kieFileSystem;
//    }
//
//
//
//    private Resource[] getRuleFiles() throws IOException {
//
//        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
//        final Resource[] resources = resourcePatternResolver.getResources("classpath*:" + RULES_PATH + "**/*.*");
//        return resources;
//
//    }
//
//
//
//    @Bean
//    public KieContainer kieContainer() throws IOException {
//        final KieRepository kieRepository = getKieServices().getRepository();
//        kieRepository.addKieModule(new KieModule() {
//            public ReleaseId getReleaseId() {
//                return kieRepository.getDefaultReleaseId();
//            }
//        });
//
//        KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());
//        kieBuilder.buildAll();
//        return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
//
//    }
//
//    private KieServices getKieServices() {
//        return KieServices.Factory.get();
//    }
//
//    @Bean
//    public KieBase kieBase() throws IOException {
//        return kieContainer().getKieBase();
//    }
//
//    @Bean
//    public KieSession kieSession() throws IOException {
//        return kieContainer().newKieSession();
//    }
//
//
//}
//
